#pragma once

#include "Entity.h"
#include "AnimationSystem.h"
#include "Animation.h"
#include "Player.h"

enum MeleeWeapons	{MW_BASE, MW_SWORD, MW_SAW, MW_CLAW};


class MeleeWeapon : public Entity 
{
protected:
	Animation weaponAnimation[4];
	Animation specialAnimation;
	int meleeType;
	bool isAttacking;
	bool isSpcAttacking;
	bool canSpcAttack;

private:
	float damage;
	float spcDamage;
	float cooldownTimer;
	float cooldownSeconds;
	float attackSpeed;
	float energyCost;
	int priceScrap;
	int priceCircuit;

	Player* owner;

public:
	MeleeWeapon() { owner = nullptr; }
	~MeleeWeapon() { /*(owner) ? owner->Release() : 0;*/ }

	virtual bool CheckCollision(IEntity* base) = 0;

	virtual void Attack() = 0;

	virtual void SpecialAttack() = 0;

	bool			IsAttacking()			{return isAttacking;}
	virtual bool	IsSpcAttacking()		{return isSpcAttacking;}

	float	GetDamage() const		{return damage;}
	void	SetDamage(float d)		{damage = d;}	

	float	GetSpcDamage() const	{return spcDamage;}
	void	SetSpcDamage(float s)	{spcDamage = s;}	

	float	GetCoolTimer() const	{return cooldownTimer;}
	void	SetCoolTimer(float t)	{cooldownTimer = t;}

	float	GetCoolSeconds() const	{return cooldownSeconds;}
	void	SetCoolSeconds(float s)	{cooldownSeconds = s;}

	float	GetAtkSpeed() const		{return attackSpeed;}
	void	SetAtkSpeed(float r)	{attackSpeed = r;}

	float	GetEnergyCost() const	{return energyCost;}
	void	SetEnergyCost(float e)	{energyCost = e;}

	int		GetMetalPrice() const	{return priceScrap;}
	void	SetMetalPrice(int p)	{priceScrap = p;}

	int		GetCircuitPrice() const	{return priceCircuit;}
	void	SetCircuitPrice(int c)	{priceCircuit = c;}

	bool	IsSpecialReady()
	{
		if(meleeType == MW_SAW)
		{
			return canSpcAttack;
		}
		else
		{
			return !isSpcAttacking;
		}
	}

	Player* GetOwner() const		{return owner;}
	void	SetOwner(Player* o)	{
		if(owner)
			owner->Release();
		owner = o;
		/*if( owner )
			owner->AddRef();*/
	}

	int GetMeleeType() const	{return meleeType;}

	virtual RECT GetRect()
	{
		RECT rect = {};

		RECT tmp = weaponAnimation[GetDirection()].GetActiveRect();;
		int width = tmp.right;
		int height = tmp.bottom;
		tmp.top += long(GetOwner()->GetY());
		tmp.bottom = height + tmp.top;
		tmp.left += long(GetOwner()->GetX());
		tmp.right = width + tmp.left;

		return tmp;
	}

	void SetAnimationIDs(int tmp[4])
	{
		for(int i = 0; i < 4; ++i)
		{
			weaponAnimation[i] = *AnimationSystem::GetInstance()->GetAnimation(tmp[i]);
		}

		owner->SetAnimation(&weaponAnimation[0]);
	}

	void SetSpecialAnimation(int id)
	{
		specialAnimation = *AnimationSystem::GetInstance()->GetAnimation(id);
	}
};	
